<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 200px auto;
        }
    </style>
</head>
<body>
    <div class="box">
            
    </div>
    <script>
        var box  = document.querySelector('.box')
     box.addEventListener('click',function(e){
         
        //  console.log(e.pageY);
        var P_y = e.pageY
        var P_x = e.pageX
        var O_y = box.offsetTop
        var O_x = box.offsetLeft
       var a =  P_y-O_y
      var b =  P_x-O_x
      console.log(box.offsetTop);
      
        console.log('y坐标为'+a+'x的坐标为'+b);
        
         
     })
    </script>
</body>
</html>